hash '__CARGO_DEFAULT_LIB_METADATA' in metadata for rustc
authorMarc-Antoine Perennou <Marc-Antoine@Perennou.com>
Thu, 15 Jun 2017 14:48:05 +0000 (16:48 +0200)
committerMarc-Antoine Perennou <Marc-Antoine@Perennou.com>
Sat, 1 Jul 2017 11:25:00 +0000 (13:25 +0200)
This will let us seed the release channel as part of the
metadata used for the hash to avoid conflicting hashes across
channels.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
src/cargo/ops/cargo_rustc/context.rs
tests/build.rs

index fa1ddd004814a3214dd40ade54d44281b603d55e..b185a2ed3ab1186cf26fce05f7871a164c316727 100644 (file)
@@ -442,16 +442,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         // Note, though, that the compiler's build system at least wants
         // path dependencies (eg libstd) to have hashes in filenames. To account for
         // that we have an extra hack here which reads the
-        // `__CARGO_DEFAULT_METADATA` environment variable and creates a
+        // `__CARGO_DEFAULT_LIB_METADATA` environment variable and creates a
         // hash in the filename if that's present.
         //
         // This environment variable should not be relied on! It's
         // just here for rustbuild. We need a more principled method
         // doing this eventually.
+        let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
         if !unit.profile.test &&
             (unit.target.is_dylib() || unit.target.is_cdylib()) &&
             unit.pkg.package_id().source_id().is_path() &&
-            !env::var("__CARGO_DEFAULT_LIB_METADATA").is_ok() {
+            !__cargo_default_lib_metadata.is_ok() {
             return None;
         }
 
@@ -491,6 +492,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             rustc.verbose_version.hash(&mut hasher);
         }
 
+        // Seed the contents of __CARGO_DEFAULT_LIB_METADATA to the hasher if present.
+        // This should be the release channel, to get a different hash for each channel.
+        if let Ok(ref channel) = __cargo_default_lib_metadata {
+            channel.hash(&mut hasher);
+        }
+
         Some(Metadata(hasher.finish()))
     }
 
index 0d533b406891df12af6bdab29d1de89c23df738d..a5293b31424116bac7a00e92ebc8cf4939e3f434 100644 (file)
@@ -849,7 +849,7 @@ suffix = env::consts::DLL_SUFFIX,
     assert_that(p.cargo("clean"), execs().with_status(0));
 
     // If you set the env-var, then we expect metadata on libbar
-    assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "1"),
+    assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "stable"),
                 execs().with_status(0).with_stderr(&format!("\
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \